#!/bin/bash
start_time=$(date +%s) # %s可以计算的是1970年以来的秒数

mkdir -p ../runlogs/
mkdir -p ../runlog/
path=../data/ebs_segment_io_records/AY283G_2022-01-01_00:00:00_2022-01-02_00:00:00/device/
filenames=$(ls $path)

for filename in $filenames; do
  data_path=${path}${filename}
  data_name=${filename%.*}
  for executable_file in trace_allGet trace_allPut trace_realRun ; do
#  for executable_file in trace_allPut ; do
    cd ../build/
    # 先删除原有的文件，否则需要sudo
    rm ../evaluation/${data_name}_${executable_file}_put.txt
    rm ../evaluation/${data_name}_${executable_file}_16_llsm.txt
    rm ../evaluation/${data_name}_${executable_file}_16_baseline.txt

    sync; echo 3 | sudo tee /proc/sys/vm/drop_caches
    ./${executable_file} -f ${data_path} -k 16 -v 64 -d ../ssd/db_${data_name} -m 7 -w > ../evaluation/${data_name}_${executable_file}_16_put.txt
#    ./a_trace_allGet -f ../db/dataset/111969901601639.txt -k 16 -v 64 -d ../ssd/db_111969901601639 -m 7 -w > ../evaluation/111969901601639_trace_allGet_put.txt

    sync; echo 3 | sudo tee /proc/sys/vm/drop_caches
    ./${executable_file} -f ${data_path} -k 16 -v 64 -d ../ssd/db_${data_name} -m 8 -u -n 10000 -i 5 $* --change_level_load > ../evaluation/${data_name}_${executable_file}_16_baseline.txt
    mkdir -p ../runlogs/${data_name}_${executable_file}_16_baseline/
    mv ../runlog/* ../runlogs/${data_name}_${executable_file}_16_baseline/


    sync; echo 3 | sudo tee /proc/sys/vm/drop_caches
    ./${executable_file} -f ${data_path} -k 16 -v 64 -d ../ssd/db_${data_name} -m 7 -w > ../evaluation/${data_name}_${executable_file}_put.txt

    sync; echo 3 | sudo tee /proc/sys/vm/drop_caches
    ./${executable_file} -f ${data_path} -k 16 -v 64 -d ../ssd/db_${data_name} -m 7 -u -n 10000 -i 5 $* --change_level_load > ../evaluation/${data_name}_${executable_file}_16_llsm.txt
    mkdir -p ../runlogs/${data_name}_${executable_file}_16_llsm/
    mv ../runlog/* ../runlogs/${data_name}_${executable_file}_16_llsm/

    cd ../learned-leveldb/
    python ./scripts/collect_results.py 1 ${data_name}_${executable_file}_16 > ../evaluation/expr_${data_name}_${executable_file}_16.txt
    cat ../evaluation/expr_${data_name}_${executable_file}_16.txt

    mv ../evaluation/num_ops.txt ../evaluation/num_ops_${data_name}_${executable_file}.txt

  done

done


end_time=$(date +%s)
cost_time=$((end_time-start_time))
echo "$0" "运行时间：$((cost_time/60))min $((cost_time%60))s"